//
//  LeaveWordCell.m
//  phmall
//
//  Created by admin on 2017/12/19.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "LeaveWordCell.h"

@implementation LeaveWordCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"SetCell";
    LeaveWordCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[LeaveWordCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.contentView.backgroundColor=[UIColor groupTableViewBackgroundColor];
        
        self.back=[[UIView alloc]init];
        self.back.backgroundColor=[UIColor whiteColor];
        ViewBorderRadius(self.back, 5, 0, [UIColor clearColor]);
        [self.contentView addSubview:self.back];
        
        
        self.head=[[UIImageView alloc]init];
        [self.back addSubview:self.head];
        self.head.image=[UIImage imageNamed:@"图片"];
        self.head.layer.cornerRadius = 5;
        
        self.name=[[UILabel alloc] init];
        self.name.text=@"玛丽苏";
        self.name.font=[UIFont systemFontOfSize:15];
        [self.back addSubview:self.name];
        
        self.time=[[UILabel alloc] init];
        [self.back addSubview:self.time];
        self.time.font=[UIFont systemFontOfSize:13];
        self.time.textColor=[UIColor colorWithHexString:@"#c5c5c5"];
        self.time.text=@"发布时间:2017-08-17";
        
        self.line=[[UIView alloc]init];
        [self.back addSubview:self.line];
        self.line.backgroundColor=[UIColor groupTableViewBackgroundColor];
        
        self.title=[[UILabel alloc] init];
        [self.back addSubview:self.title];
        self.title.font=[UIFont systemFontOfSize:15];
        self.title.numberOfLines=0;
        self.title.text=@"获取指定宽度width,字体大小fontSize,字符串value的高度,字符串value的高度,字符串value的高度,字符串value的高度";
        
        
        self.text=[[UILabel alloc] init];
        [self.back addSubview:self.text];
        self.text.font=[UIFont systemFontOfSize:13];
        self.text.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.text.numberOfLines=0;
        self.text.text=@"获取指定宽度width,字体大小fontSize,字符串value的高度,字符串value的高度,字符串value的高度,字符串value的高度";
        
        self.bline=[[UIView alloc]init];
        [self.back addSubview:self.bline];
        self.bline.backgroundColor=[UIColor groupTableViewBackgroundColor];
        
        self.relation=[[UILabel alloc] init];
        [self.back addSubview:self.relation];
        self.relation.font=[UIFont systemFontOfSize:13];
        self.relation.text=@"联系详情";
        
        self.leave=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.back addSubview:self.leave];
        [self.leave setImage:[UIImage imageNamed:@"前往"] forState:UIControlStateNormal];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(10);
        make.right.bottom.offset(-10);
    }];
    
    [self.head mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(10);
        make.width.height.offset(50).priorityHigh();
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.head.mas_right).offset(5);
        make.top.equalTo(self.head).offset(5);
    }];
    
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.name);
        make.bottom.equalTo(self.head).offset(-5);
    }];
    
    [self.line mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.head.mas_bottom).offset(10);
        make.left.offset(0);
        make.right.offset(0);
        make.height.offset(0.5);
        
    }];

    self.title.preferredMaxLayoutWidth = SCREEN_WIDTH-40;
    [self.title setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line.mas_bottom).offset(10).priorityHigh();
        make.left.offset(10).priorityHigh();
        make.width.offset(SCREEN_WIDTH-40);
    }];
    
    self.text.preferredMaxLayoutWidth = SCREEN_WIDTH-40;
    [self.text setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    [self.text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.title.mas_bottom).offset(5);
        make.left.offset(10).priorityHigh();
        make.width.offset(SCREEN_WIDTH-40);
    }];

    [self.bline mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.text.mas_bottom).offset(10);
        make.left.offset(10);
        make.right.offset(-10);
        make.height.offset(0.5);
    }];
    
    [self.relation mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.centerY.equalTo(self.back.mas_bottom).offset(-22);
    }];
    
    [self.leave mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.equalTo(self.back.mas_bottom).offset(-22);
    }];
    
}
+ (CGFloat)calculateHeight{
    CGSize titleSize = [@"获取指定宽度width,字体大小fontSize,字符串value的高度,字符串value的高度,字符串value的高度,字符串value的高度" boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-40, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    
    CGSize textSize = [@"获取指定宽度width,字体大小fontSize,字符串value的高度,字符串value的高度,字符串value的高度,字符串value的高度" boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-40, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size;
    NSLog(@"%f-----%f",textSize.height,titleSize.height);
    return 70+textSize.height+titleSize.height+25+44+10;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
